package com.vip8.recorder.service.config;

import com.aliyun.oss.ClientConfiguration;
import com.aliyun.oss.OSSClient;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class OssConfig {
    @Value("${oss.endPoint}")
    private String endPoint;

    @Value("${oss.accessKeyId}")
    private String accessKeyId;

    @Value("${oss.accessKeySecret}")
    private String accessKeySecret;

    public static final String REGION_CN_HANGZHOU = "cn-hangzhou";


    @Bean
    public OSSClient ossClient() {
        ClientConfiguration cfg = new ClientConfiguration();
        cfg.setMaxConnections(200);
        cfg.setConnectionTimeout(5000);
        cfg.setSocketTimeout(5000);
        cfg.setMaxErrorRetry(3);
        return new OSSClient(endPoint, accessKeyId, accessKeySecret, cfg);
    }

    @Bean
    public DefaultAcsClient acsClient() {
        IClientProfile profile = DefaultProfile.getProfile(REGION_CN_HANGZHOU, accessKeyId, accessKeySecret);
        return new DefaultAcsClient((profile));
    }

}
